﻿using System;

namespace Transformable_Engine_v2.Engine.Animation.Trajectory
{
    public class ExponentialEasing : BaseTrajectory
    {
        private readonly Easing _easing;

        public ExponentialEasing(Easing easing)
        {
            _easing = easing;
        }


        public override double GetPercentageProgression(double elapsedDurationTime)
        {
            switch (_easing)
            {
                case Easing.EaseIn:
                    return GetEaseIn(elapsedDurationTime);
                case Easing.EaseOut:
                    return GetEaseOut(elapsedDurationTime);
                case Easing.EaseInAndOut:
                    return GetEaseInAndOut(elapsedDurationTime);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        private double GetEaseOut(double elapsedDurationTime)
        {
            return -Math.Pow(2, -10*elapsedDurationTime) + 1;
        }

        private double GetEaseIn(double elapsedDurationTime)
        {
            return Math.Pow(2, 10 * (elapsedDurationTime - 1));
        }

        private double GetEaseInAndOut(double elapsedDurationTime)
        {
            if (elapsedDurationTime < 0.5)
                return 0.5 * Math.Pow(2, 10 * (2 * elapsedDurationTime - 1));

            return 0.5 * (-Math.Pow(2, -10 * (2 * elapsedDurationTime- 1)) + 2);

        }
    }
} 